#include "StdThread.h"
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>



struct StdThread
{
    pthread_t threadID;
};

Thread *InitThread(void *(*funcPtr)(void *), void *arg)
{
    Thread *t = (Thread*)malloc(sizeof(Thread));
    if(t == NULL)
    {
        printf("thread malloc error!\n");
        return NULL;
    }
    
    pthread_create(&t->threadID,NULL,funcPtr,arg);
    return t;
}

void* ThreadJoin(Thread *t)
{
    void *value;
    pthread_join(t->threadID,&value);
    return value;
}

void ThreadDetach(Thread *t)
{
    pthread_detach(t->threadID);
}

void ThreadCancel(Thread *t)
{
    pthread_cancel(t->threadID);
}

unsigned long int GetThreadId(Thread *t)
{
    return t->threadID;
}

void ClearThread(Thread *t)
{
    if(t == NULL)
        return;
    free(t);
}
